import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-12-11
 * Time: 15:12
 */
public class Solution2 {
    public int K;
    public int kthSmallest(TreeNode root, int k) {
        K = k;
        return kthSmallest(root);
    }
    private int kthSmallest(TreeNode root) {
        if(root == null) return -1;
        int leftFind = kthSmallest(root.left, K);
        if(leftFind != -1) return leftFind;
        if(K == 1) return root.val;
        K--;
        int rightFind = kthSmallest(root.right, K);
        return rightFind;
    }
}
